/* shared.h generated Sat Nov  7 13:21:53 2009 GMT+2 */
#ifndef _SHARED_H_
#define _SHARED_H_


/*** Source: dev/shared/dllexport.h ***/
#ifdef _WIN32
  #ifdef __LCC__
    #define DLLEXPORT(x) __declspec(dllexport) __stdcall x
  #else
    #define DLLEXPORT(x) __declspec(dllexport) x __stdcall
  #endif
#else
  #define DLLEXPORT(x) x
#endif

/*** Source: dev/shared/shared_def.h ***/
#ifdef _WIN32
  #define EXTCALL __stdcall
#else
  #define EXTCALL 
#endif
typedef int CMPFUNC(void*,void*);
typedef void EXTCALL FREEFUNC(void*);

/*** Source: dev/shared/linkedlist.h ***/
typedef struct _llistnode
{
  void *               x;
  struct _llistnode *  prev;
  struct _llistnode *  next;
  struct _llist     *  list;
}ListNode;
typedef struct _llist
{
  ListNode		*first;
  ListNode		*last;
  unsigned int	 nodes;
}LinkedList;

/*** Source: dev/shared/n0sha1.h ***/

/*** Source: dev/shared/non0string.h ***/
typedef struct _non0string
{
  unsigned char* s;
  unsigned int l;
}non0string;

/*** Source: dev/shared/helpers.h ***/

/*** Source: dev/shared/prqueue.h ***/
typedef struct _pqueue {
	LinkedList *q;
	CMPFUNC    *cmpfunc;
} PQueue;

/*** Source: dev/shared/filename.h ***/

/*** Source: dev/shared/tree.h ***/
typedef struct _treenode
{
  void *              x;
  struct _treenode *  parent;
  struct _treenode *  left;
  struct _treenode *  right;
  int                 height;
}TreeNode;
typedef struct _btree
{
  TreeNode *   root;
  CMPFUNC  *cmpfunc;
}BTree;

/*** Source: dev/shared/debugs.h ***/
#ifdef MEM_DEBUG
  void *mem_debug_pointer;
  #define dmalloc(size) (mem_debug_pointer = malloc(size)); fprintf(stderr, "malloc(%p) at %s:%d\n", mem_debug_pointer, __FILE__, __LINE__)
  #define dfree(pointer) fprintf(stderr, "free  (%p) at %s:%d\n", pointer, __FILE__, __LINE__); free(pointer)
#else
  #define dmalloc(size) malloc(size)
  #define dfree(pointer) free(pointer)
#endif
#ifdef DEBUG
  #define DBG(x) x
#else
  #define DBG(x) 
#endif

/*** Source: dev/shared/n0sha1.c ***/
DLLIMPORT(non0string*) n0sha1(non0string *message) ;

/*** Source: dev/shared/helpers.c ***/
DLLIMPORT(LinkedList*) SplitString(non0string *snString, const char *szSep) ;
DLLIMPORT(void) EvalEscapes(char *retstr, char *original) ;
DLLIMPORT(unsigned int) hex2int(char *cc, int multiplier) ;
DLLIMPORT(non0string*) shorten_to(non0string *original, size_t max_length) ;
DLLIMPORT(void) DumpObject(void *x, size_t l) ;

/*** Source: dev/shared/filename.c ***/

/*** Source: dev/shared/linkedlist.c ***/
DLLIMPORT(LinkedList*) LLcreate(void) ;
DLLIMPORT(void) LLdelete(LinkedList *l, FREEFUNC *freefunc) ;
DLLIMPORT(ListNode*) LLaddFirst(LinkedList* l,void* x) ;
DLLIMPORT(ListNode*) LLaddLast(LinkedList* l,void* x) ;
DLLIMPORT(ListNode*) LLaddBefore(ListNode* n,void* x) ;
DLLIMPORT(ListNode*) LLaddAfter(ListNode* n,void* x) ;
DLLIMPORT(void*) LLdelNode(ListNode *n) ;
DLLIMPORT(void*) LLdelFirst(LinkedList* l) ;
DLLIMPORT(void*) LLdelLast(LinkedList* l) ;
DLLIMPORT(LinkedList*) LLmerge(LinkedList *first, LinkedList *second) ;

/*** Source: dev/shared/non0string.c ***/
DLLIMPORT(non0string*) n0salloc(size_t v_size) ;
DLLIMPORT(void) n0sfree(non0string *v) ;
DLLIMPORT(unsigned char*) n0strstr(non0string* nstr, const unsigned char* zstr) ;
DLLIMPORT(int) n0strcmp(non0string *str1, non0string *str2) ;
DLLIMPORT(non0string*) char2non(const unsigned char* x) ;
DLLIMPORT(non0string*) n0scopy(non0string* x) ;
DLLIMPORT(unsigned char*) non2char(non0string* x) ;
DLLIMPORT(unsigned int) n0tou(non0string *source) ;
DLLIMPORT(unsigned long long int) n0tolu(non0string *source) ;

/*** Source: dev/shared/tree.c ***/
DLLIMPORT(BTree*) newBTree(CMPFUNC*cmpfunc) ;
DLLIMPORT(TreeNode*) BTreeFind(BTree* tree, void* x) ;
DLLIMPORT(TreeNode*) BTreeAdd(BTree *tree, void *x) ;
DLLIMPORT(TreeNode*) BTreeFindOrAdd(BTree *tree, void *x) ;
DLLIMPORT(void*) BTreeReplace(BTree *tree, void *x) ;
DLLIMPORT(int) BTreeDel(BTree *tree, TreeNode *n) ;
DLLIMPORT(void) freeBTree(BTree *tree, FREEFUNC *freefunc) ;
DLLIMPORT(void) freeBTreeNode(TreeNode *n, FREEFUNC *freefunc) ;
DLLIMPORT(TreeNode*) iterateTree(BTree *tree) ;
DLLIMPORT(TreeNode*) iterateTreeNext(TreeNode *orig) ;
DLLIMPORT(void) BTree_debug_dump(BTree *tree) ;

/*** Source: dev/shared/prqueue.c ***/
DLLIMPORT(PQueue*) newPQueue(CMPFUNC *cmpfunc) ;
DLLIMPORT(ListNode*) PQueueInsert(PQueue* q, void *data) ;
DLLIMPORT(void *) PQueuePeek(PQueue *q) ;
DLLIMPORT(void *) PQueuePoll(PQueue *q) ;
DLLIMPORT(void *) PQueueCancel(PQueue *q, void *data) ;
DLLIMPORT(void *) PQueueFind(PQueue *q, void *data) ;
#endif
